home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / MacPerl 5.1.3 / Mac_Perl_513_src / perl5.002 / lib / Config.pm < prev    next >
Encoding:
Perl POD Document  |  1997-01-21  |  10.9 KB  |  612 lines  |  [TEXT/MPS ]

  1. package Config;
  2. use Exporter ();
  3. @ISA = (Exporter);
  4. @EXPORT = qw(%Config);
  5. @EXPORT_OK = qw(myconfig config_sh config_vars);
  6.  
  7. $] == 5.00201
  8.   or die "Perl lib version (5.00201) doesn't match executable version ($])\n";
  9.  
  10. # This file was created by configpm when Perl was built. Any changes
  11. # made to this file will be lost the next time perl is built.
  12.  
  13. ##
  14. ## Manually created configuration file for Macintii
  15. ## Configuration time:    07Apr96
  16. ## Configured by:     Matthias Neeracher <neeri@iis.ee.ethz.ch>
  17. ## Target system:     Apple Macintosh
  18. #
  19.  
  20. my $config_sh = <<'!END!';
  21. extensions='DB_File DynaLoader Fcntl GDBM_File NDBM_File POSIX SDBM_File Socket'
  22. static_ext='DynaLoader'
  23. osname='MacOS'
  24. osvers='7.5'
  25. archlibexp=''
  26. archname=''
  27. installarchlib=''
  28. cc='C'
  29. ccflags=''
  30. cppflags=''
  31. dlsrc=''
  32. libpth=''
  33. libs=''
  34. prefix=''
  35. installprivlib=''
  36. privlibexp=''
  37. sig_name=''
  38. so=''
  39. sharpbang=''
  40. shsharp=''
  41. startsh=''
  42. Author='neeri'
  43. CONFIG='true'
  44. Date=''
  45. Header=''
  46. Id=''
  47. Locker=''
  48. Log=''
  49. Mcc='C'
  50. PATCHLEVEL='0'
  51. RCSfile=''
  52. Revision=''
  53. Source=''
  54. State=''
  55. afs=''
  56. alignbytes=''
  57. aphostname=''
  58. archlib=''
  59. awk='gawk'
  60. bash=''
  61. bin=''
  62. binexp=''
  63. bison='bison'
  64. byacc='byacc'
  65. byteorder='4321'
  66. c=''
  67. castflags='0'
  68. cat='Catenate'
  69. cccdlflags=''
  70. ccdlflags=''
  71. cf_by=''
  72. cf_time=''
  73. chgrp=''
  74. chmod=''
  75. chown=''
  76. clocktype='clock_t'
  77. compress='Stuffit'
  78. contains=''
  79. cp='Duplicate'
  80. cpio=''
  81. cpp='C -e'
  82. cpp_stuff=''
  83. cpplast=''
  84. cppminus=''
  85. cpprun=''
  86. cppstdin=''
  87. cryptlib=''
  88. csh=''
  89. d_Gconvert='undef'
  90. d_access='undef'
  91. d_alarm='undef'
  92. d_archlib='undef'
  93. d_attrib='undef'
  94. d_bcmp='define'
  95. d_bcopy='define'
  96. d_bsdpgrp='undef'
  97. d_bzero='define'
  98. d_casti32='32'
  99. d_castneg='define'
  100. d_charsprf='undef'
  101. d_charvspr='undef'
  102. d_chown='undef'
  103. d_chroot='undef'
  104. d_chsize='undef'
  105. d_closedir='define'
  106. d_const='define'
  107. d_crypt='undef'
  108. d_csh='undef'
  109. d_cuserid='undef'
  110. d_dbl_dig='define'
  111. d_difftime='define'
  112. d_dirnamlen='define'
  113. d_dlerror='undef'
  114. d_dlopen='undef'
  115. d_dlsymun='undef'
  116. d_dosuid='undef'
  117. d_drem='undef'
  118. d_dup2='2'
  119. d_eunice='undef'
  120. d_fchmod='define'
  121. d_fchown='undef'
  122. d_fcntl='define'
  123. d_fd_macros='define'
  124. d_fd_set='define'
  125. d_fds_bits='define'
  126. d_fgetpos='define'
  127. d_flexfnam='define'
  128. d_flock='undef'
  129. d_fmod='define'
  130. d_fork='undef'
  131. d_fpathconf='undef'
  132. d_fsetpos='define'
  133. d_getgrps='undef'
  134. d_gethent='undef'
  135. d_gethname='define'
  136. d_getlogin='undef'
  137. d_getpgrp2='undef'
  138. d_getpgrp='undef'
  139. d_getppid='undef'
  140. d_getprior='undef'
  141. d_group='undef'
  142. d_htonl='define'
  143. d_index='undef'
  144. d_isascii='define'
  145. d_killpg='undef'
  146. d_link='undef'
  147. d_linuxstd='undef'
  148. d_locconv='undef'
  149. d_lockf='undef'
  150. d_lstat='define'
  151. d_mblen='undef'
  152. d_mbstowcs='define'
  153. d_mbtowc='define'
  154. d_memcmp='define'
  155. d_memcpy='define'
  156. d_memmove='define'
  157. d_memset='define'
  158. d_mkdir='define'
  159. d_mkfifo='undef'
  160. d_mktime='define'
  161. d_msg='undef'
  162. d_msgctl='undef'
  163. d_msgget='undef'
  164. d_msgrcv='undef'
  165. d_msgsnd='undef'
  166. d_mymalloc='undef'
  167. d_nice='undef'
  168. d_oldsock='undef'
  169. d_open3='3'
  170. d_passwd='undef'
  171. d_pathconf='undef'
  172. d_pause='undef'
  173. d_phostname='undef'
  174. d_pipe='undef'
  175. d_portable='undef'
  176. d_pwage='undef'
  177. d_pwchange='undef'
  178. d_pwclass='undef'
  179. d_pwcomment='undef'
  180. d_pwexpire='undef'
  181. d_pwquota='undef'
  182. d_readdir='define'
  183. d_readlink='define'
  184. d_rename='define'
  185. d_rewinddir='define'
  186. d_rmdir='define'
  187. d_safebcpy='define'
  188. d_safemcpy='undef'
  189. d_seekdir='define'
  190. d_select='define'
  191. d_sem='undef'
  192. d_semctl='undef'
  193. d_semget='undef'
  194. d_semop='undef'
  195. d_setegid='undef'
  196. d_seteuid='undef'
  197. d_setlinebuf='undef'
  198. d_setlocale='define'
  199. d_setpgid='undef'
  200. d_setpgrp2='2'
  201. d_setpgrp='undef'
  202. d_setprior='undef'
  203. d_setregid='undef'
  204. d_setresgid='undef'
  205. d_setresuid='undef'
  206. d_setreuid='undef'
  207. d_setrgid='undef'
  208. d_setruid='undef'
  209. d_setsid='undef'
  210. d_shm='undef'
  211. d_shmat='undef'
  212. d_shmatprototype='undef'
  213. d_shmctl='undef'
  214. d_shmdt='undef'
  215. d_shmget='undef'
  216. d_socket='define'
  217. d_sockpair='undef'
  218. d_statblks='undef'
  219. d_stdstdio='define'
  220. d_strchr='define'
  221. d_strcoll='undef'
  222. d_strctcpy='undef'
  223. d_strerrm='undef'
  224. d_strerror='define'
  225. d_strxfrm='define'
  226. d_suidsafe='undef'
  227. d_symlink='define'
  228. d_syscall='undef'
  229. d_sysconf='undef'
  230. d_sysernlst='undef'
  231. d_syserrlst='undef'
  232. d_system='undef'
  233. d_tcgetpgrp='undef'
  234. d_tcsetpgrp='undef'
  235. d_telldir='define'
  236. d_time='define'
  237. d_times='define'
  238. d_truncate='undef'
  239. d_tzname='undef'
  240. d_umask='define'
  241. d_uname='undef'
  242. d_vfork='undef'
  243. d_void_closedir='undef'
  244. d_voidsig='undef'
  245. d_voidtty='undef'
  246. d_volatile='define'
  247. d_vprintf='define'
  248. d_wait4='undef'
  249. d_waitpid='undef'
  250. d_wcstombs='define'
  251. d_wctomb='define'
  252. d_xenix='undef'
  253. date='Date'
  254. defvoidused=''
  255. direntrytype='dirent'
  256. dlext=''
  257. echo='Echo'
  258. egrep='egrep'
  259. emacs='$emacs'
  260. eunicefix=':'
  261. expr='Evaluate'
  262. find=''
  263. flex='flex'
  264. fpostype='fpos_t'
  265. gcc='gcc'
  266. gccversion=''
  267. gidtype=''
  268. glibpth=''
  269. grep='grep'
  270. groupcat=''
  271. groupstype=''
  272. h_fcntl='true'
  273. h_sysfile='false'
  274. hint=''
  275. hostcat=''
  276. huge=''
  277. i_bsdioctl=''
  278. i_db='define'
  279. i_dbm='define'
  280. i_dirent='define'
  281. i_dld=''
  282. i_dlfcn=''
  283. i_fcntl='define'
  284. i_float='define'
  285. i_gdbm='undef'
  286. i_grp='undef'
  287. i_limits='define'
  288. i_malloc='undef'
  289. i_math='define'
  290. i_memory='define'
  291. i_ndbm='define'
  292. i_neterrno='undef'
  293. i_niin='undef'
  294. i_pwd='undef'
  295. i_sgtty=''
  296. i_stdarg='define'
  297. i_stddef='define'
  298. i_stdlib='define'
  299. i_string='define'
  300. i_sysdir='undef'
  301. i_sysfile='undef'
  302. i_sysfilio=''
  303. i_sysin='define'
  304. i_sysioctl='define'
  305. i_sysndir=''
  306. i_sysparam=''
  307. i_sysselct=''
  308. i_syssockio=''
  309. i_systime='define'
  310. i_systimek=''
  311. i_systimes=''
  312. i_termio=''
  313. i_termios=''
  314. i_time='define'
  315. i_unistd='define'
  316. i_utime=''
  317. i_varargs=''
  318. i_varhdr='stdarg.h'
  319. i_vfork=''
  320. incpath=''
  321. inews=''
  322. installbin=''
  323. installmansrc=''
  324. installscript=''
  325. intsize='32'
  326. known_extensions='DB_File DynaLoader Fcntl GDBM_File NDBM_File ODBM_File POSIX SDBM_File Socket'
  327. ksh=''
  328. large=''
  329. lddlflags=''
  330. ldflags=''
  331. less=''
  332. libc=''
  333. libswanted=''
  334. line='line'
  335. lint=''
  336. lkflags=''
  337. ln=''
  338. lns=''
  339. lp=''
  340. lpr='Print'
  341. ls='Directory'
  342. lseektype=''
  343. mail=''
  344. mailx=''
  345. make='BuildProgram'
  346. mallocobj=''
  347. mallocsrc=''
  348. malloctype=''
  349. manext=''
  350. mansrc=''
  351. mansrcexp=''
  352. medium=''
  353. mips=''
  354. mips_type=''
  355. mkdir='NewFolder'
  356. models=''
  357. modetype=''
  358. more=''
  359. mv='Move'
  360. mydomain=''
  361. myhostname=''
  362. myuname=''
  363. n=''
  364. nm_opt=''
  365. nroff=''
  366. optimize=''
  367. orderlib=''
  368. package=''
  369. passcat=''
  370. perl='Perl'
  371. pg=''
  372. phostname=''
  373. plibpth=''
  374. pmake=''
  375. pr=''
  376. privlib=''
  377. prototype=''
  378. randbits=''
  379. ranlib=''
  380. rm='Delete'
  381. rmail=''
  382. runnm=''
  383. scriptdir=''
  384. scriptdirexp=''
  385. sed='sed'
  386. selecttype=''
  387. sendmail=''
  388. sh=''
  389. shar=''
  390. shmattype=''
  391. signal_t='signal_t'
  392. sizetype=''
  393. sleep=''
  394. smail=''
  395. small=''
  396. sockethdr=''
  397. socketlib=''
  398. sort='Sort'
  399. spackage=''
  400. spitshell=''
  401. split=''
  402. ssizetype=''
  403. startperl='Perl -Sx "{0}" {"Parameters"}; Exit {Status}\n#!perl'
  404. stdchar=''
  405. strings='define'
  406. submit=''
  407. sysman=''
  408. tail=''
  409. tar=''
  410. tbl=''
  411. test=''
  412. timeincl='time.h'
  413. timetype='time_t'
  414. touch='SetFile -m .'
  415. tr=''
  416. troff=''
  417. uidtype=''
  418. uname=''
  419. uniq=''
  420. usedl=''
  421. usemymalloc=''
  422. usenm=''
  423. useposix='true'
  424. usevfork=''
  425. usrinc=''
  426. uuname=''
  427. vi=''
  428. voidflags=''
  429. xlibpth=''
  430. yacc=''
  431. yaccflags=''
  432. zcat=''
  433. !END!
  434.  
  435. my $summary = <<'!END!';
  436. Summary of my $package ($baserev patchlevel $PATCHLEVEL subversion $SUBVERSION) configuration:
  437.   Platform:
  438.     osname=$osname, osver=$osvers, archname=$archname
  439.     uname='$myuname'
  440.     hint=$hint, useposix=$useposix, d_sigaction=$d_sigaction
  441.   Compiler:
  442.     cc='$cc', optimize='$optimize', gccversion=$gccversion
  443.     cppflags='$cppflags'
  444.     ccflags ='$ccflags'
  445.     stdchar='$stdchar', d_stdstdio=$d_stdstdio, usevfork=$usevfork
  446.     voidflags=$voidflags, castflags=$castflags, d_casti32=$d_casti32, d_castneg=$d_castneg
  447.     intsize=$intsize, alignbytes=$alignbytes, usemymalloc=$usemymalloc, randbits=$randbits
  448.   Linker and Libraries:
  449.     ld='$ld', ldflags ='$ldflags'
  450.     libpth=$libpth
  451.     libs=$libs
  452.     libc=$libc, so=$so
  453.   Dynamic Linking:
  454.     dlsrc=$dlsrc, dlext=$dlext, d_dlsymun=$d_dlsymun, ccdlflags='$ccdlflags'
  455.     cccdlflags='$cccdlflags', lddlflags='$lddlflags'
  456.  
  457. !END!
  458. my $summary_expanded = 0;
  459.  
  460. sub myconfig {
  461.     return $summary if $summary_expanded;
  462.     $summary =~ s/\$(\w+)/$Config{$1}/ge;
  463.     $summary_expanded = 1;
  464.     $summary;
  465. }
  466.  
  467. tie %Config, Config;
  468. sub TIEHASH { bless {} }
  469. sub FETCH { 
  470.     # check for cached value (which maybe undef so we use exists not defined)
  471.     return $_[0]->{$_[1]} if (exists $_[0]->{$_[1]});
  472.  
  473.     my($value); # search for the item in the big $config_sh string
  474.     return undef unless (($value) = $config_sh =~ m/^$_[1]='(.*)'\s*$/m);
  475.  
  476.     $value = undef if $value eq 'undef'; # So we can say "if $Config{'foo'}".
  477.     $value =~ s/\\n/\n/g;         # macintosh
  478.     $_[0]->{$_[1]} = $value; # cache it
  479.     return $value;
  480. }
  481.  
  482. my $prevpos = 0;
  483.  
  484. sub FIRSTKEY {
  485.     $prevpos = 0;
  486.     my($key) = $config_sh =~ m/^(.*?)=/;
  487.     $key;
  488. }
  489.  
  490. sub NEXTKEY {
  491.     my $pos = index($config_sh, "\n", $prevpos) + 1;
  492.     my $len = index($config_sh, "=", $pos) - $pos;
  493.     $prevpos = $pos;
  494.     $len > 0 ? substr($config_sh, $pos, $len) : undef;
  495. }
  496.  
  497. sub EXISTS { 
  498.      exists($_[0]->{$_[1]})  or  $config_sh =~ m/^$_[1]=/m; 
  499. }
  500.  
  501. sub STORE  { die "\%Config::Config is read-only\n" }
  502. sub DELETE { &STORE }
  503. sub CLEAR  { &STORE }
  504.  
  505.  
  506. sub config_sh {
  507.     $config_sh
  508. }
  509. sub config_vars {
  510.     foreach(@_){
  511.     my $v=(exists $Config{$_}) ? $Config{$_} : 'UNKNOWN';
  512.     $v='undef' unless defined $v;
  513.     print "$_='$v';\n";
  514.     }
  515. }
  516.  
  517. 1;
  518. __END__
  519.  
  520. =head1 NAME
  521.  
  522. Config - access Perl configuration information
  523.  
  524. =head1 SYNOPSIS
  525.  
  526.     use Config;
  527.     if ($Config{'cc'} =~ /gcc/) {
  528.     print "built by gcc\n";
  529.     } 
  530.  
  531.     use Config qw(myconfig config_sh config_vars);
  532.  
  533.     print myconfig();
  534.  
  535.     print config_sh();
  536.  
  537.     config_vars(qw(osname archname));
  538.  
  539.  
  540. =head1 DESCRIPTION
  541.  
  542. The Config module contains all the information that was available to
  543. the C<Configure> program at Perl build time (over 900 values).
  544.  
  545. Shell variables from the F<config.sh> file (written by Configure) are
  546. stored in the readonly-variable C<%Config>, indexed by their names.
  547.  
  548. Values stored in config.sh as 'undef' are returned as undefined
  549. values.  The perl C<exists> function can be used to check is a
  550. named variable exists.
  551.  
  552. =over 4
  553.  
  554. =item myconfig()
  555.  
  556. Returns a textual summary of the major perl configuration values.
  557. See also C<-V> in L<perlrun/Switches>.
  558.  
  559. =item config_sh()
  560.  
  561. Returns the entire perl configuration information in the form of the
  562. original config.sh shell variable assignment script.
  563.  
  564. =item config_vars(@names)
  565.  
  566. Prints to STDOUT the values of the named configuration variable. Each is
  567. printed on a separate line in the form:
  568.  
  569.   name='value';
  570.  
  571. Names which are unknown are output as C<name='UNKNOWN';>.
  572. See also C<-V:name> in L<perlrun/Switches>.
  573.  
  574. =back
  575.  
  576. =head1 EXAMPLE
  577.  
  578. Here's a more sophisticated example of using %Config:
  579.  
  580.     use Config;
  581.  
  582.     defined $Config{sig_name} || die "No sigs?";
  583.     foreach $name (split(' ', $Config{sig_name})) {
  584.     $signo{$name} = $i;
  585.     $signame[$i] = $name;
  586.     $i++;
  587.     }   
  588.  
  589.     print "signal #17 = $signame[17]\n";
  590.     if ($signo{ALRM}) { 
  591.     print "SIGALRM is $signo{ALRM}\n";
  592.     }   
  593.  
  594. =head1 WARNING
  595.  
  596. Because this information is not stored within the perl executable
  597. itself it is possible (but unlikely) that the information does not
  598. relate to the actual perl binary which is being used to access it.
  599.  
  600. The Config module is installed into the architecture and version
  601. specific library directory ($Config{installarchlib}) and it checks the
  602. perl version number when loaded.
  603.  
  604. =head1 NOTE
  605.  
  606. This module contains a good example of how to use tie to implement a
  607. cache and an example of how to make a tied variable readonly to those
  608. outside of it.
  609.  
  610. =cut
  611.  
  612.